<!-- View all / Admin / offer / donate / listing -->
<?php
include("functions/database.php");
$result = mysqli_query($con,"SELECT * FROM DonateList WHERE Deleted = 0 ORDER BY Timestamp");
?>
<article
ng-init="
<?php
  if(isset($_SESSION['logged']) && $_SESSION['logged']){echo 'isAdmin = true;';};
  while($row = mysqli_fetch_array($result))
  {
    echo "list.push({";
    if ($row['Type']==0) {echo "type: 'D',";};
    if ($row['Type']==1) {echo "type: 'R',";};
    echo "timestamp: '" . $row['Timestamp'] . "',";
    echo "name: '" . $row['Name'] . "',";
    echo "location: '" . $row['Location'] . "',";
    echo "contact: '" . $row['Contact'] . "',";
    echo "details: '" . $row['Details'] . "',";
    echo "flags: '" . $row['Flags'] . "',";
    echo "help: '" . $row['Help'] . "',";
    if (!empty($row['Password'])) {echo "hasPass: true,";} else {echo "hasPass: false,";};
    echo "id: '" .  base64_encode($row['ID']) . "'";
    echo "});";
  }
?>
"
>

<header>
  <p><?php if(isset($_SESSION['logged']) && $_SESSION['logged']){echo 'Welcome, ' . $_SESSION['Username'] . ". You are the admin!";}; ?></p>
  <hr />
  <div class="halfhead">
    <span class="table-filter" ng-click="setFilter(ALL)" ng-class="{active: (type == ALL)}"><i class="fa fa-star"></i> All </span>
    <span class="table-filter" ng-click="setFilter(REQUESTS)" ng-class="{active: (type == REQUESTS)}"><i class="fa fa-home"></i> Requests </span>
    <span class="table-filter" ng-click="setFilter(DONATIONS)" ng-class="{active: (type == DONATIONS)}"><i class="fa fa-heart"></i> Donations </span>
  </div>
  <div class="halfhead"><input type="text" placeholder="Search for supplies, or a relief center" ng-model="query"/></div>
  <hr />
  <style>
#main-list-body { vertical-align:top; }
#main-list-body > tr > td { padding-top: 2em; }
  </style>
</header>

<table id="donatelist">
  <thead>
    <tr>
      <th width="20">Type</th>
      <th width="250">Date</th>
      <th width="250">Name</th>
      <th width="600">Details</th>
      <th width="300">Help</th>
      <th width="260">Flags</th>
      <th width="100">Edit</th>
      <th width="100" ui-if="isAdmin">Delete</th>

    </tr>
  </thead>

  <tbody id="main-list-body">
    <tr ng-repeat="item in list | filter:query | filter:{type: type} | orderBy:'-timestamp'">
       <td>
        <div ui-if="item.type  == 'R'">
          <span data-tooltip class="has-tip" title="Request for Help">
            <a class="iwanttohelp" style="background-color:#29ABE2;"><i class="fa fa-home"></i></a>
          </span>
        </div>
        <div ui-if="item.type  == 'D'">
          <span data-tooltip class="has-tip" title="Donate Supplies">
            <a class="iwanttohelp" style="background-color:#29ABE2;"><i class="fa fa-heart">&nbsp;</i></a>
          </span>
        </div>
      </td>
      <td ng-bind="item.timestamp"> <div ui-if="isOld(item.timestamp)">[!]</div> </td>
      <td> <div ng-bind="item.name"></div> </td>
      <td> 
        <div><strong>Location:</strong></div><div ng-bind="item.location"></div><br>
        <div><strong>Contact:</strong></div><div ng-bind="item.contact"></div><br> 
        <div><strong>Details:</strong></div><div ng-bind="item.details"></div><br> 
      </td>
      <td><span data-tooltip class="has-tip" title="Connect with this list item and collaborate!"><a class="iwanttohelp" ng-click="openModal(item, HELP)">Connect! ({{item.help}})</a></span><br /><br /><a ng-href="connect.php?id={{item.id}}">&nbsp; View</a></td>
      <td>
        <span data-tooltip class="has-tip" title="Report suspicious or fraudulent listings" ui-if="item.flags < 5" ng-click="openModal(item, FLAG)">
          <a href="#" class="iwanttohelp" style="background-color: #F67577;"><i class="fa fa-flag"></i> Flag&nbsp;<span ui-if="isAdmin">{{item.flags}}</span> </a>
        </span>
        <span data-tooltip class="has-tip" title="This item has been reported to be suspicious or fraudulent. Beware!" ui-if="item.flags > 4" ng-click="openModal(item, FLAG)">
          <a href="#" class="iwanttohelp" style="background-color: #E20004;"><i class="fa fa-flag"></i> Flagged &nbsp;&nbsp; <span ui-if="isAdmin">{{item.flags}}</span> </a>
        </span>
      </td>
      <td> <a ng-click="openModal(item, PASSWORD)" ui-if="isAdmin || item.hasPass">Edit</a> </td>
      <td ui-if="isAdmin"> <a ng-click="openModal(item, DELETE)">Delete</a> </td>
    </tr>

  </tbody>
</table>

<h6 class="half"></h6>

</article>